package com.zlq.cn.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum QuestionTypeEnum {
    // 0：判断题，1：单选题，2：多选题，3：填空题，4：简答题
    JUDGE("判断题", "0"),
    SINGLE("单选题", "1"),
    MULTIPLE("多选题", "2"),
    COMPLETION("填空题", "3"),
    SHORT_ANSWER("简答题", "4"),
    ;
    private final String title;
    private final String type;

    public static final QuestionTypeEnum[] VALUES = values();
    public static final Map<String, QuestionTypeEnum> nameMap = Arrays.stream(values())
            .collect(Collectors.toMap(QuestionTypeEnum::getTitle, Function.identity()));

    public static String nameToType(String name) {
        return Optional.ofNullable(nameMap.get(name)).map(QuestionTypeEnum::getType).orElse(null);
    }
}
